package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.bean.SysDevice;
import com.qf.dto.R;
import com.qf.service.SysDeviceService;
import com.qf.utils.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
 *  @author Administrator
 *  @version V1.0
 *  @Project smartdeviceplatgorm
 *  @Package com.qf.controller
 *  @Description
 *  @Date2022/3/22 0022 16:47
 */
@RestController
@RequestMapping("/device")
public class SysDeviceController {
    private SysDeviceService sysDeviceService;
    @Autowired
    public void setSysDeviceService(SysDeviceService sysDeviceService) {
        this.sysDeviceService = sysDeviceService;
    }

    @PostMapping("/add")
    public R addSysDevice(@RequestBody SysDevice sysDevice) {
        sysDeviceService.addSysDevice(sysDevice);
        return R.setOk();
    }



    @PostMapping("/all")
    public R findBySelf(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer limit) {
        PageInfo<SysDevice> bySelf = sysDeviceService.findBySelf(page, limit);
        long count=bySelf.getTotal();
        List<SysDevice> deviceList=bySelf.getList();
        return R.getR(ResultCode.SUCCESS,"success",deviceList,count);
    }
}
